<?php include _include(APP_PATH.'view/htm/header.inc.htm');?>

<!--{hook user_create_start.htm}-->

<div class="row">
	<div class="col-lg-6 mx-auto">
		<!--{hook user_create_card_before.htm}-->
		<div class="card">
			<div class="card-header">
				<?php echo lang('user_create');?>
				<!--{hook user_create_title_after.htm}-->
			</div>
			<div class="card-body">
				<form action="<?php echo url('user-create');?>" method="post" id="form">
				
					<div class="form-group input-group">
						<div class="input-group-prepend">
							<span class="input-group-text"><i class="icon-mobile"></i></span>
						</div>
						<input type="mobile" class="form-control" placeholder="<?php echo lang('mobile');?>" name="mobile" id="mobile" required>
					</div>
					
					<!--{hook user_create_mobile_after.htm}-->
					
					<div class="form-group input-group">
						<div class="input-group-prepend">
							<span class="input-group-text"><i class="icon-user"></i></span>
						</div>
						<input type="text" class="form-control" placeholder="<?php echo lang('username');?>" name="username" id="username">
					</div>
					
					<!--{hook user_create_username_after.htm}-->
					
					<div class="form-group input-group">
						<div class="input-group-prepend">
							<span class="input-group-text"><i class="icon-lock"></i></span>
						</div>
						<input type="password" class="form-control" placeholder="<?php echo lang('password');?>" id="password" name="password">
						<div class="invalid-feedback"></div>
					</div>
					
					<!--{hook user_create_password_after.htm}-->
					
					<?php if($kv_mobile['user_create_on']) { ?>
					<div class="media">
						<div class="media-body">
							<div class="form-group input-group">
								<div class="input-group-prepend">
									<span class="input-group-text"><i class="icon-barcode"></i></span>
								</div>
								<input type="text" class="form-control" placeholder="<?php echo lang('verify_code');?>" name="code" id="code">
							</div>
						</div>
						<div class="align-self-center ml-1">
							<button type="submit" class="btn btn-primary btn-sm ml-3 form-group" id="sendcode" data-loading-text="<?php echo lang('sending');?>..." action="<?php echo url('user-send_code-user_create');?>"><?php echo lang('send_code');?></button>
						</div>
					</div>
					<?php } ?>
					
					<!--{hook user_create_code_after.htm}-->
					
					<hr class="mt-0" />
					<div class="form-group">
						<button type="submit" class="btn btn-primary btn-block" id="submit" data-loading-text="<?php echo lang('submiting');?>..." <?php if($kv_mobile['user_create_on']) { ?>disabled<?php } ?>><?php echo lang('next_step');?></button>
					</div>
					
					<!--{hook user_create_submit_after.htm}-->
					
					<div class="media">
						<div>
							<!--{hook user_create_form_footer_left.htm}-->
						</div>
						<div class="media-body text-right">
							<!--{hook user_create_form_footer_right_start.htm}-->
							<a href="<?php echo url('user-login');?>" class="text-muted"><small><?php echo lang('user_login');?></small></a>
							<?php if($kv_mobile['user_resetpw_on']) { ?>
							<a href="<?php echo url('user-resetpw');?>" class="text-muted ml-3"><small><?php echo lang('forgot_pw');?></small></a>
							<?php } ?>
							<!--{hook user_create_form_footer_right_end.htm}-->
						</div>
					</div>
					
				</form>
			</div>
		</div>
		<!--{hook user_create_card_after.htm}-->
	</div>
</div>

<!--{hook user_create_end.htm}-->

<?php include _include(APP_PATH.'view/htm/footer.inc.htm');?>

<script src="<?php echo $conf['view_url'];?>js/md5.js"></script>

<script>
var jform = $('#form');
var jsubmit = $('#submit');
var jsendsubmit = $('#sendcode');
var referer = '<?php echo http_referer();?>';
jsendsubmit.on('click', function() {
	jform.reset();
	jsendsubmit.button('loading');
	var postdata = jform.serialize();
	$.xpost(jsendsubmit.attr('action'), postdata, function(code, message) {
		if(code == 0) {
			$('#code').focus();
			var t = 60; // 倒计时
			jsendsubmit.button('<?php echo lang('user_send_sucessfully');?> 60 ');
			jsubmit.button('reset');
			// 倒计时，重新发送
			var handler = setInterval(function() {
				jsendsubmit.button('<?php echo lang('user_send_sucessfully');?> '+(--t)+' ');
				if(t == 0) {
					clearInterval(handler);
					jsendsubmit.button('reset');
				}
			}, 1000);
		} else if(code < 0) {
			$.alert(message, -1);
			jsendsubmit.button('reset');
		} else {
			jform.find('[name="'+code+'"]').alert(message).focus();
			jsendsubmit.button('reset');
		}
	});
	return false;
});

jform.on('submit', function() {
	var postdata = jform.serializeObject();
	jsubmit.button('loading');
	postdata.password = $.md5(postdata.password);
	$.xpost(jform.attr('action'), postdata, function(code, message) {
		if(code == 0) {
			
			// ----------> 弹出层预留
			if(typeof arg1 != 'undefined') {
				var jmodal = arg1;
			}
			if(typeof arg2 != 'undefined') {
				var callback = arg2;
				callback(message);
			}
			
			$.alert(message);
			jsubmit.button(message).delay(3000).location(referer);
		} else if(code < 0) {
			$.alert(message, -1);
			jsubmit.button('reset');
		} else {
			jform.find('[name="'+code+'"]').alert(message).focus();
			jsubmit.button('reset');
		}
	});
	return false;
});

</script>

<!--{hook user_create_js.htm}-->